import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { Nyt7BusinessEntityVO, Nyt7BusinessEntityForm, Nyt7BusinessEntityQuery } from '@/api/Nyt7BusinessEntity/Nyt7BusinessEntity/types';

/**
 * 查询经营主体列表
 * @param query
 * @returns {*}
 */

export const listNyt7BusinessEntity = (query?: Nyt7BusinessEntityQuery): AxiosPromise<Nyt7BusinessEntityVO[]> => {
  return request({
    url: '/Nyt7BusinessEntity/Nyt7BusinessEntity/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询经营主体详细
 * @param id
 */
export const getNyt7BusinessEntity = (id: string | number): AxiosPromise<Nyt7BusinessEntityVO> => {
  return request({
    url: '/Nyt7BusinessEntity/Nyt7BusinessEntity/' + id,
    method: 'get'
  });
};

/**
 * 新增经营主体
 * @param data
 */
export const addNyt7BusinessEntity = (data: Nyt7BusinessEntityForm) => {
  return request({
    url: '/Nyt7BusinessEntity/Nyt7BusinessEntity',
    method: 'post',
    data: data
  });
};

/**
 * 修改经营主体
 * @param data
 */
export const updateNyt7BusinessEntity = (data: Nyt7BusinessEntityForm) => {
  return request({
    url: '/Nyt7BusinessEntity/Nyt7BusinessEntity',
    method: 'put',
    data: data
  });
};

/**
 * 删除经营主体
 * @param id
 */
export const delNyt7BusinessEntity = (id: string | number | Array<string | number>) => {
  return request({
    url: '/Nyt7BusinessEntity/Nyt7BusinessEntity/' + id,
    method: 'delete'
  });
};

/**
 * 取消评级
 * @param id 
 */
export const cancelRating = (id: string | number) => {
  return request({
    url: '/Nyt7BusinessEntity/Nyt7BusinessEntity/cancelRating/' + id,
    method: 'put'
  });
};

/**
 * 取消认证
 * @param id 
 */
export const cancelCertification = (id: string | number) => {
  return request({
    url: '/Nyt7BusinessEntity/Nyt7BusinessEntity/cancelCertification/' + id,
    method: 'put'
  });
};

/**
 * 添加导入Excel的方法
 * @param file
 */
export const importExcel = (file: File) => {
  const formData = new FormData();
  formData.append('file', file);
  return request({
    url: '/Nyt7BusinessEntity/Nyt7BusinessEntity/import',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
};
